var ircbot = require('../ircbot');
var assert = require('assert');
var util = require ('util');

var IrcBotUnitTests = {

   testattach: function ()
   {
      try
      {
         var bot = ircbot.create();
         bot.debug = true;
         bot.connect('chat.freenode.net', 6667, 'test_user_js');   
         assert(bot != null);
         bot.onconnect = function(thebot)
         {
            var handler = thebot.attach(5, '#test_channel', [ 'Hello World', 'This is', 'Fantastic' ]);
            assert(handler != null);
         };
         bot.onmessage = function(owner, dest, msg)
         {
            console.log(util.format('Message from %s to %s: "%s"', owner, dest, msg));
         }
         setTimeout(function() 
         {
            bot.disconnect();
         }, 40000);
      } catch(e)
      {
         assert.fail("Exception thrown: " + e);
      }
   }
}

for(var e in IrcBotUnitTests)
{
   IrcBotUnitTests[e]();
}
